/**
 * 前台-首页：自定义JS事件
 * */


////AD图片宽度自适应
//function getAd(){
//    var ads = [
//        {id:1,link:'imgs/carousel-01.png'},
//        {id:2,link:'imgs/carousel-02.png'},
//    ];
//    $('#ad > img').width(cw);
//    $('#ad > .img').width(cw);
//    $('#adbody').width(cw*ads.length);
//    var h = '', i;
//    for (i=0; i<ads.length; i++) {
//        h += '<div class="img" style="width:'+cw+'px;float:left;"><img src="'+ads[i].link+'"></div>';
//    }
//    adNum = ads.length; adKey = 1;
//    $('#adbody').html(h).width(cw*adNum);
//    //console.log(cw,ch,$('#adbody').width());
//}


//AD图片宽度自适应
function shouye(){
    $.ajax({
        type: 'post',
        url: domain+'shouye',
        data: {},
        success: function (res) {
            res = JSON.parse(res);
            console.log(res);
            if (res.code!=0) {
                pop({msg:res.msg}); return
            }
            var ad = res.data.ads;
            var intro = res.data.intro;
            var agenda = res.data.agenda;
            var videoList = res.data.videos.data, videoTotal = res.data.videos.total;
            var sponsor = res.data.sponsors;
            getAdHtml(ad);
            getIntroHtml(intro);
            getAgendaHtml(agenda);
            getVideoHtml({data:videoList,total:videoTotal,start:0});
            getSponsorHtml(sponsor);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//AD字符串
function getAdHtml(d){
    $('#ad > img').width(cw);
    $('#ad > .img').width(cw);
    $('#adbody').width(cw*d.length);
    var h = '', i;
    for (i=0; i<d.length; i++) {
        h += '<div class="img" style="width:'+cw+'px;float:left;"><img src="'+d[i].img+'"></div>';
    }
    adNum = d.length; adKey = 1;
    $('#adbody').html(h).width(cw*adNum);
}


//大会介绍
function getIntroHtml(d){
    $('.dhdetail').html(d.detail);
    $('#dhimg').html('<img src="'+d.img+'" width="600">');
}


//大会议程
function getAgendaHtml(d){
    $('.ycimg').html('<img src="'+d.img+'" width="1200">');
}


//大会视频
function getVideoHtml(e){
    var d = e.data, total = e.total, start = e.start;
    var h = '', i, title, img, link;
    for (i=0; i<d.length; i++) {
        title = d[i].title; img = d[i].img; link = d[i].link;
        h += '<div class="box" onclick="window.open(\''+link+'\',\'_blank\')">';
        h += '<div class="img">';
        h += '<img src="'+img+'"/>';
        h += '</div>';
        h += '<div class="txt">'+title+'</div>';
        h += '</div>';
        videoList.push(d[i]);
    }
    $('#xgsp').html(h);
    videoTotal = total;
    videoPageStart = start;
}


//大会视频分页：oper==1上一页，2下一页
function getVideoIndex(oper){
    var videoLimit = 0, videoStart = 0;;
    if (oper==1) {
        if (videoPageStart==0) {
            pop({msg:'没有前一页视频了'}); return
        }
        videoStart = videoPageStart - 1;
    } else {
        videoLimit = videoPageLimit * (videoPageStart + 1);
        if (videoLimit>=videoTotal) {
            pop({msg:'没有更多视频了'}); return
        }
        videoStart = videoPageStart + 1;
    }
    $.ajax({
        type: 'post',
        url: domain+'shouye/video/index',
        data: {start:videoStart},
        success: function (res) {
            res = JSON.parse(res);
            console.log(res);
            if (res.code!=0) {
                pop({msg:res.msg}); return
            }
            var d = res.data, total = res.data.total;
            getVideoHtml({data:d,total:total,start:videoStart});
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//赞助商字符串
function getSponsorHtml(d){
    var h = '', i;
    for (i=0; i<d.length; i++) {
        h += '<div class="img">';
        h += '<img src="'+d[i].img+'"/>';
        h += '</div>';
    }
    $('#zzsbody').html(h);
}


////大会相关视频
//function xgsp(){
//    var d = [
//        {id:1,title:'吉林大学团队—一款以合成生物学为基础设计的生命游戏',link:''},
//        {id:2,title:'吉林大学团队—一款以合成生物学为基础设计的生命游戏',link:''},
//        {id:3,title:'吉林大学团队—一款以合成生物学为基础设计的生命游戏',link:''},
//        {id:4,title:'吉林大学团队—一款以合成生物学为基础设计的生命游戏',link:''},
//    ];
//    var h = '', i;
//    for (i=0; i<d.length; i++) {
//        h += '<div class="box">';
//        h += '<div class="img"></div>';
//        h += '<div class="txt">'+d[i].title+'</div>';
//        h += '</div>';
//    }
//    $('#xgsp').html(h);
//}


////赞助商
//function zzs(){
//    var d = [
//        {id:1,link:''},
//        {id:2,link:''},
//        {id:3,link:''},
//        {id:4,link:''},
//        {id:5,link:''},
//    ];
//    var h = '', i;
//    for (i=0; i<d.length; i++) {
//        h += '<div class="img"></div>';
//    }
//    $('#zzsbody').html(h);
//}


//AD右移动画
function aniAdLeft(){
    console.log('左箭头右移');
    adWid = adWid==0 ? cw : adWid*1+cw;
    if (adKey==1) {
        adWid = -cw*(adNum-1); adKey = adNum;
        $('#adbody').animate({left:adWid},500);
    } else {
        adKey --;
    }
    console.log(adKey,adWid);
    $('#adbody').animate({left:adWid},500,function(){
    });
}


//AD左移动画
function aniAdRight(){
    console.log('右箭头左移');
    adWid = adWid==0 ? -cw : adWid*1-cw;
    if (adKey==adNum) {
        adWid = 0; adKey = 1;
        $('#adbody').animate({left:0},500);
        return
    } else {
        adKey ++;
    }
    console.log(adKey,adWid);
    $('#adbody').animate({left:adWid},500,function(){
    });
}